﻿using SBSimpleLib.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;


namespace SBSimpleLib
{
    public abstract class Ticker
    {
        private static String TAG = "TCK";
        private int numSeconds = SECOND;

        public const int QUARTER = 250;
        public const int HALF = 500;
        public const int SECOND = 1000;

        private bool shouldStop = false;

        public Ticker(int seconds)
        {
            numSeconds = seconds;
        }

        public void run()
        {
            Logger.info(TAG, "Ticker Start.");
            while (!shouldStop)
            {
                tick();
                Thread.Sleep(numSeconds);
            }
            shouldStop = false;
            Logger.info(TAG, "Ticker Exit.");
        }

        public void tick()
        {
            
            if (MyWoW.ObjectManager.ObjectManager.Me != null && MyWoW.ObjectManager.ObjectManager.Me.Name != "")
            {
                // DEBUG Logger.debug(TAG, MyWoW.ObjectManager.ObjectManager.Me.Name + ". tick()");
                doTick();
            }
            else
            {
                Logger.debug(TAG, "Char not loged. tick()");
            }
        }

        public void requestStop()
        {
            shouldStop = true;
        }

        public abstract void doTick();

        public int NumSeconds { get { return numSeconds; } }
    }
}
